package cn.tedu.zhyl.nurseManager.controller;

import cn.tedu.zhyl.base.response.JsonResult;
import cn.tedu.zhyl.base.response.PageResponse;
import cn.tedu.zhyl.base.response.StatusCode;
import cn.tedu.zhyl.nurseManager.pojo.dto.NurseProjectQuery;
import cn.tedu.zhyl.nurseManager.pojo.dto.NurseProjectSaveParam;
import cn.tedu.zhyl.nurseManager.pojo.vo.NurseProjectVO;
import cn.tedu.zhyl.nurseManager.pojo.vo.NursingItemVO;
import cn.tedu.zhyl.nurseManager.service.NurseProjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/nurse/projects/")
public class NurseProjectController {
    @Autowired
    NurseProjectService nurseProjectService;

    @GetMapping("select/{page}/{limit}")
    public JsonResult<PageResponse<NurseProjectVO>> select(NurseProjectQuery nurseProjectQuery,
                               @PathVariable Integer page,
                               @PathVariable Integer limit){
        log.debug("NurseProjectController.select param:{}",nurseProjectQuery);
        PageResponse<NurseProjectVO> nurseProjectVOList = nurseProjectService.select(nurseProjectQuery,page,limit);
        log.debug("NurseProjectController.select result:{}",nurseProjectVOList);
        return JsonResult.build(nurseProjectVOList, StatusCode.SUCCESS_OPERATION);
    }

    @GetMapping("getItemList")
    public JsonResult<List<NursingItemVO>> getList(){
        List<NursingItemVO> list = nurseProjectService.getList();
        return JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult save(@RequestBody NurseProjectSaveParam nurseProjectSaveParam){
        nurseProjectService.save(nurseProjectSaveParam);
        return JsonResult.ok();
    }

    @GetMapping("updateStatus")
    public JsonResult updateStatus(String status,Long id){
        log.debug("修改状态参数为:"+status+"id:"+id);
        nurseProjectService.updateStatus(status,id);
        return JsonResult.ok();
    }

    @GetMapping("delete")
    public JsonResult delete(Long id){
        log.debug("删除参数id:"+id);
        nurseProjectService.delete(id);
        return JsonResult.ok();
    }

}
